﻿using EmitDebugging;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Spackle.Testing;
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Reflection.Emit;

namespace EmitDebugging.Tests
{
	[TestClass]
	public sealed class CodeDocumentTests : CoreTests
	{
		[TestMethod]
		public void CallDisposeAfterDisposing()
		{
			CodeDocument document = null;

			using(document = new CodeDocument(0, 0))
			{
			}

			document.Dispose();
		}

		[TestMethod, ExpectedException(typeof(ObjectDisposedException))]
		public void CallWriteTextWithCodeLineAfterDisposing()
		{
			CodeDocument document = null;

			using(document = new CodeDocument(0, 0))
			{
			}

			document.WriteText(null as CodeLine);
		}

		[TestMethod, ExpectedException(typeof(ObjectDisposedException))]
		public void CallWriteTextWithListOfCodeLineILGeneratorISymbolDocumentWriterAfterDisposing()
		{
			CodeDocument document = null;

			using(document = new CodeDocument(0, 0))
			{
			}

			document.WriteText(null as List<CodeLine>, 
				null as ILGenerator, null as ISymbolDocumentWriter);
		}

		[TestMethod, ExpectedException(typeof(ObjectDisposedException))]
		public void CallWriteTextWithIEnumerableOfCodeLineILGeneratorISymbolDocumentWriterAfterDisposing()
		{
			CodeDocument document = null;

			using(document = new CodeDocument(0, 0))
			{
			}

			document.WriteText(null as IEnumerable<CodeLine>,
				null as ILGenerator, null as ISymbolDocumentWriter);
		}

		[TestMethod, ExpectedException(typeof(ObjectDisposedException))]
		public void CallWriteTextWithCodeLineILGeneratorISymbolDocumentWriterAfterDisposing()
		{
			CodeDocument document = null;

			using(document = new CodeDocument(0, 0))
			{
			}

			document.WriteText(null as CodeLine,
				null as ILGenerator, null as ISymbolDocumentWriter);
		}
		
		[TestMethod]
		public void WriteMultipleLinesWithDifferentDebuggableStates()
		{
			CodeDocument document = null;

			using(document = new CodeDocument(0, 0))
			{
				document.WriteText(new List<CodeLine>()
				{
					new CodeLine("x", true),
					new CodeLine("x", false),
					new CodeLine("x", true)
				}, null, null);
			}		
		}
	}
}
